using System.Collections;
using UnityEngine;

public class MenuUIController : MonoBehaviour
{
	public static MenuUIController instance;

	public static BeginShow beginshow;

	public Transform UIrootParent;

	public ShowController showui;

	public GameObject jikuobj;

	public JikuCamera jikucam;

	public MenuLoad menuload;

	public UplineUI uplineui;

	public GarageUI garageui;

	public BattleUI battleui;

	public LevelUI levelui;

	public StartUI startui;

	public MainUI mainui;

	public ChallengeUI challengeui;

	public RewardUI rewardui;

	public UpgradeUI upgradeui;

	public hitinfoUI hitinfoui;

	public ChargeUI chargeui;

	public ShowPieceUI showpieceui;

	public JunxianUI junxianui;

    public PrivacyUI privacyui;

    public GetPieceUI getpieceui;

	public Chall_infoUI challinfoui;

	public ExitUI exitui;

	public DailyBonusUI dailybonusui;

	public optionUI optionui;

	public CreditsUI creditsui;

	public SaleUI saleui1;

	public SaleUI saleui2;

	public EffectUI effectui;

	public GetRewards getreward;

	public boxinfoUI boxinfoui;

	public ADrewards AdReward;

	public GuideUI guideui;

	private GameObject loadobj;

	private void Awake()
	{
		if (instance == null)
		{
			instance = this;
		}
		GlobalInf.SetBegin();
	}

	private void Start()
	{
		Platform.cancleAllNotification();
		enable_loading();
		StartCoroutine("initobj");
	}

	private IEnumerator initobj()
	{
		for (float timer = 0f; timer < 0.8f; timer += Time.deltaTime)
		{
			yield return 0;
		}
		bool close = jikuobj == null;
		if (close) UnityVersionUtil.SetActiveRecursive(m_jikuobj, state: false);
	}

	private GameObject m_jikuobj
	{
		get
		{
			if (jikuobj == null)
			{
				jikuobj = (UnityEngine.Object.Instantiate(Resources.Load("obj/garage")) as GameObject);
				jikucam = jikuobj.GetComponent<JikuCamera>();
			}
			return jikuobj;
		}
	}

	public void firstshow()
	{
		MonoInstance<AudioController>.instance.play(AudioType.Menu_BG, 0f);
		switch (beginshow)
		{
			case BeginShow.main:
				enable_upline();
				show_planetime();
				enable_mainui();
				break;
			case BeginShow.level:
				enable_upline();
				enable_mainui();
				disable_mainui();
				enable_battleui();
				battleui.AutoEnterLevel();
				break;
			case BeginShow.level_energy:
				enable_upline();
				enable_mainui();
				disable_mainui();
				enable_battleui();
				enable_chargeui(2);
				break;
			case BeginShow.challenge:
				enable_upline();
				enable_mainui();
				mainui.OnClickchallengeBtn(null);
				break;
			case BeginShow.garage:
				enable_upline();
				enable_mainui();
				mainui.OnClickstoreBtn(null);
				break;
		}
	}

	public void AutoSaleui()
	{
		MenuBackController.instance.HomeFun();
		mainui.OnClicksaleBtn(null);
	}

	public void AutoFexdui(int levelind)
	{
		disable_getpieceui();
		if (MenuBackController.instance.curstate == MenuUIState.garageui)
		{
			disable_garage(isres: true);
			show_planetime();
		}
		else if (MenuBackController.instance.curstate == MenuUIState.upgradeui)
		{
			disable_upgradeui();
			disable_garage(isres: true);
			show_planetime();
		}
		if (levelind < 0)
		{
			switch (levelind)
			{
				case -1:
					enable_challengeui(1);
					break;
				case -2:
					enable_challengeui(2);
					break;
				case -3:
					enable_challengeui(3);
					break;
				case -4:
					enable_challengeui();
					break;
				case -5:
					enable_rewardui(0);
					break;
			}
		}
		else
		{
			enable_battleui();
			battleui.AutoEnterFexLevel(levelind);
			enable_startui(levelind);
		}
	}

	public void enable_loading()
	{
		menuload.enable();
		MenuBackController.instance.ChangeMenuUIstate(MenuUIState.loading);
	}

	public void show_planetime()
	{
		if (showui != null)
		{
			showui.enable();
		}
	}

	public void disappear_planetime()
	{
		if (showui != null)
		{
			showui.disable();
		}
	}

	public void enable_effectui(Vector3 start, int type)
	{
		effectui.enable(start, type);
	}

	public void enable_saleui1()
	{
		/* if (MenuBackController.instance.curstate != MenuUIState.sale1)
		{
			saleui1.enable();
			MenuBackController.instance.ChangeMenuUIstate(MenuUIState.sale1);
		} */
	}

	public void enable_getreward(int id, bool isone)
	{
		getreward.enable(id, isone);
		MenuBackController.instance.ChangeMenuUIstate(MenuUIState.getreward);
	}

	public void enable_adreward()
	{
		AdReward.enable();
		MenuBackController.instance.ChangeMenuUIstate(MenuUIState.ADReward);
	}

	public void disable_saleui1()
	{
		saleui1.disable();
	}

	public void enable_saleui2()
	{
		/* if (MenuBackController.instance.curstate != MenuUIState.sale2)
		{
			saleui2.enable();
			MenuBackController.instance.ChangeMenuUIstate(MenuUIState.sale2);
		} */
	}

	public void disable_saleui2()
	{
		saleui2.disable();
	}

	public void enable_creditsui()
	{
		creditsui.enable();
		MenuBackController.instance.ChangeMenuUIstate(MenuUIState.creditsui);
	}

	public void disable_creditsui()
	{
		creditsui.disable();
	}

	public void enable_optionui()
	{
		optionui.enable();
		MenuBackController.instance.ChangeMenuUIstate(MenuUIState.optionui);
	}

	public void disable_optionui()
	{
		optionui.disable();
	}

	public void enable_dailybonusui()
	{
		dailybonusui.enable();
		MenuBackController.instance.ChangeMenuUIstate(MenuUIState.bonusui);
	}

	public void disable_dailybonusui()
	{
		dailybonusui.disable();
	}

	public void enable_exitui()
	{
		exitui.enable();
		MenuBackController.instance.ChangeMenuUIstate(MenuUIState.exitui);
	}

	public void disable_exitui()
	{
		exitui.disable();
	}

	public void enable_guideui(bool isone)
	{
		guideui.enable(isone);
	}

	public void enable_boxinfoui()
	{
		boxinfoui.enable();
		MenuBackController.instance.ChangeMenuUIstate(MenuUIState.boxinfo);
	}

	public void disable_boxinfoui()
	{
		boxinfoui.disable();
	}

	public void enable_challinfoui(int id)
	{
		challinfoui.enable(id);
		MenuBackController.instance.ChangeMenuUIstate(MenuUIState.challinfo);
	}

	public void disable_challinfoui()
	{
		challinfoui.disable();
	}

	public void enable_getpieceui(PieceData pd)
	{
		getpieceui.enable(pd);
		MenuBackController.instance.ChangeMenuUIstate(MenuUIState.getpiece);
	}

	public void disable_getpieceui()
	{
		getpieceui.disable();
	}

	public void enable_junxianui()
	{
		junxianui.enable();
		MenuBackController.instance.ChangeMenuUIstate(MenuUIState.showjunxian);
	}

	public void disable_junxianui()
	{
		junxianui.disable();
	}

    public void enable_privacyui()
    {
        privacyui.enable();
        MenuBackController.instance.ChangeMenuUIstate(MenuUIState.showprivacy);
    }

    public void disable_privacyui()
    {
        privacyui.disable();
    }

    public void enable_pieceui(PieceData pd)
	{
		showpieceui.enable(pd);
		MenuBackController.instance.ChangeMenuUIstate(MenuUIState.showpieceui);
	}

	public void disable_pieceui()
	{
		showpieceui.disable();
	}

	public void enable_hitinfoui(hitinfoid curid, string str = null)
	{
		hitinfoui.enable(curid, str);
	}

	public void enable_chargeui(int num)
	{
		Platform.HideFeatureView();
		chargeui.enable(num);
		MenuBackController.instance.ChangeMenuUIstate(MenuUIState.chargeui);
	}

	public void disable_chargeui()
	{
		chargeui.disable();
		MenuBackController.instance.BackMenuUIstate();
	}

	public void enable_upgradeui(int planeindex)
	{
		upgradeui.enable(planeindex);
		MenuBackController.instance.ChangeMenuUIstate(MenuUIState.upgradeui);
	}

	public void disable_upgradeui()
	{
		upgradeui.disable();
		MenuBackController.instance.BackMenuUIstate();
	}

	public void enable_rewardui(int item = 1)
	{
		rewardui.enable(item);
		MenuBackController.instance.ChangeMenuUIstate(MenuUIState.rewardui);
		if (!AdManager1.instance.ShieldAddress)
		{
			AdManager.single.ShowNative();
		}
	}

	public void disable_rewardui()
	{
		rewardui.disable();
		MenuBackController.instance.BackMenuUIstate();
	}

	public void enable_mainui()
	{
		mainui.enable();
		MenuBackController.instance.ChangeMenuUIstate(MenuUIState.mainui);
		if (battleui == null)
		{
			loadui_res(MenuUIState.battleui);
		}
		if (!AdManager1.instance.ShieldAddress)
		{
			AdManager.single.ShowBanner();
		}
	}

	public void disable_mainui()
	{
		mainui.disable();
		MenuBackController.instance.BackMenuUIstate();
	}

	public void enable_challengeui(int id = 0)
	{
		if (id == -1)
		{
			id = 0;
		}
		Platform.ShowFeatureView();
		disappear_planetime();
		challengeui.enable(id);
		MenuBackController.instance.ChangeMenuUIstate(MenuUIState.challengeui);
		if (!AdManager1.instance.ShieldAddress)
		{
			AdManager.single.ShowNative();
		}
	}

	public void disable_challengeui()
	{
		Platform.HideFeatureView();
		challengeui.disable();
		MenuBackController.instance.BackMenuUIstate();
	}

	// 开始ui
	public void enable_startui(int lvnum)
	{
		if (!GlobalInf.menuuifirst)
		{
			Platform.ShowFeatureView();
		}
		startui.enable(lvnum);
		MenuBackController.instance.ChangeMenuUIstate(MenuUIState.startui);
		if (!AdManager1.instance.ShieldAddress)
		{
			AdManager.single.ShowNative();
		}
	}

	public void disable_startui()
	{
		startui.disable();
		MenuBackController.instance.BackMenuUIstate();
	}

	// 战役ui
	public void enable_battleui()
	{
		if (levelui == null)
		{
			loadui_res(MenuUIState.levelui);
		}
		disappear_planetime();
		battleui.enable();
		MenuBackController.instance.ChangeMenuUIstate(MenuUIState.battleui);
		if (!AdManager1.instance.ShieldAddress)
		{
			AdManager.single.ShowNative();
		}
	}

	public void disable_battleui()
	{
		battleui.disable();
		MenuBackController.instance.BackMenuUIstate();
	}

	// 关卡ui
	public void enable_levelui(int lvnum)
	{
		if (!GlobalInf.menuuifirst)
		{
			Platform.ShowFeatureView();
		}
		levelui.enable(lvnum);
		MenuBackController.instance.ChangeMenuUIstate(MenuUIState.levelui);
		if (!AdManager1.instance.ShieldAddress)
		{
			AdManager.single.ShowNative();
		}
	}

	public void disable_levelui()
	{
		if (!GlobalInf.menuuifirst)
		{
			Platform.HideFeatureView();
		}
		levelui.disable();
		MenuBackController.instance.BackMenuUIstate();
	}

	public void enable_jiku()
	{
		UnityVersionUtil.SetActiveRecursive(m_jikuobj, state: true);
	}

	public void disable_jiku()
	{
		UnityVersionUtil.SetActiveRecursive(m_jikuobj, state: false);
	}

	// 停机棚
	public void enable_garage(int num)
	{
		disappear_planetime();
		enable_jiku();
		garageui.enable(num);
		MenuBackController.instance.ChangeMenuUIstate(MenuUIState.garageui);
		if (!AdManager1.instance.ShieldAddress)
		{
			AdManager.single.ShowNative();
		}
	}

	public void disable_garage(bool isres)
	{
		garageui.disable(isres);
		disable_jiku();
		MenuBackController.instance.BackMenuUIstate();
	}

	public void enable_upline()
	{
		uplineui.enable();
	}

	public void disable_upline()
	{
		uplineui.disable();
	}

	public void updateenergy()
	{
		uplineui.infoUpdate();
		if (chargeui != null)
		{
			chargeui.showenergynum();
		}
	}

	public void nextscene()
	{
		Platform.HideFeatureView();
		UnityEngine.SceneManagement.SceneManager.LoadScene("PlaneFight");
		MidLoading.loadlevel = 2;
		GlobalInf.gameover = false;
	}

	private void OnDestroy()
	{
		if (instance != null)
		{
			instance = null;
		}
	}

	public void loadui_res(MenuUIState needstate)
	{
		switch (needstate)
		{
			case MenuUIState.hitinfoui:
			case MenuUIState.confirm_buyplane:
			case MenuUIState.confirm_unlocklevel:
			case MenuUIState.showplaneui:
			case MenuUIState.openboxui:
				break;
			case MenuUIState.garageui:
				UnityEngine.Debug.Log("garageui load......");
				loadobj = (UnityEngine.Object.Instantiate(Resources.Load("UI/menuui/garageUI")) as GameObject);
				loadobj.transform.parent = UIrootParent;
				loadobj.transform.localPosition = Vector3.zero;
				loadobj.transform.localScale = new Vector3(1f, 1f, 1f);
				garageui = loadobj.GetComponent<GarageUI>();
				UnityVersionUtil.SetActiveRecursive(loadobj, state: false);
				break;
			case MenuUIState.battleui:
				loadobj = (UnityEngine.Object.Instantiate(Resources.Load("UI/menuui/BattleUI")) as GameObject);
				loadobj.transform.parent = UIrootParent;
				loadobj.transform.localPosition = Vector3.zero;
				loadobj.transform.localScale = new Vector3(1f, 1f, 1f);
				battleui = loadobj.GetComponent<BattleUI>();
				UnityVersionUtil.SetActiveRecursive(loadobj, state: false);
				break;
			case MenuUIState.levelui:
				loadobj = (UnityEngine.Object.Instantiate(Resources.Load("UI/menuui/LevelUI")) as GameObject);
				loadobj.transform.parent = UIrootParent;
				loadobj.transform.localPosition = Vector3.zero;
				loadobj.transform.localScale = new Vector3(1f, 1f, 1f);
				levelui = loadobj.GetComponent<LevelUI>();
				UnityVersionUtil.SetActiveRecursive(loadobj, state: false);
				break;
			case MenuUIState.startui:
				UnityEngine.Debug.Log("startui load......");
				loadobj = (UnityEngine.Object.Instantiate(Resources.Load("UI/menuui/StartUI")) as GameObject);
				loadobj.transform.parent = UIrootParent;
				loadobj.transform.localPosition = Vector3.zero;
				loadobj.transform.localScale = new Vector3(1f, 1f, 1f);
				startui = loadobj.GetComponent<StartUI>();
				UnityVersionUtil.SetActiveRecursive(loadobj, state: false);
				break;
			case MenuUIState.challengeui:
				UnityEngine.Debug.Log("challengeui load......");
				loadobj = (UnityEngine.Object.Instantiate(Resources.Load("UI/menuui/challengeUI")) as GameObject);
				loadobj.transform.parent = UIrootParent;
				loadobj.transform.localPosition = Vector3.zero;
				loadobj.transform.localScale = new Vector3(1f, 1f, 1f);
				challengeui = loadobj.GetComponent<ChallengeUI>();
				UnityVersionUtil.SetActiveRecursive(loadobj, state: false);
				break;
			case MenuUIState.rewardui:
				UnityEngine.Debug.Log("garageui load......");
				loadobj = (UnityEngine.Object.Instantiate(Resources.Load("UI/menuui/rewardUI")) as GameObject);
				loadobj.transform.parent = UIrootParent;
				loadobj.transform.localPosition = Vector3.zero;
				loadobj.transform.localScale = new Vector3(1f, 1f, 1f);
				rewardui = loadobj.GetComponent<RewardUI>();
				UnityVersionUtil.SetActiveRecursive(loadobj, state: false);
				break;
			case MenuUIState.upgradeui:
				UnityEngine.Debug.Log("upgradeui load......");
				loadobj = (UnityEngine.Object.Instantiate(Resources.Load("UI/menuui/upgradeUI")) as GameObject);
				loadobj.transform.parent = UIrootParent;
				loadobj.transform.localPosition = Vector3.zero;
				loadobj.transform.localScale = new Vector3(1f, 1f, 1f);
				upgradeui = loadobj.GetComponent<UpgradeUI>();
				UnityVersionUtil.SetActiveRecursive(loadobj, state: false);
				break;
			case MenuUIState.chargeui:
				UnityEngine.Debug.Log("chargeui load......");
				loadobj = (UnityEngine.Object.Instantiate(Resources.Load("UI/menuui/ChargeUI")) as GameObject);
				loadobj.transform.parent = UIrootParent;
				loadobj.transform.localPosition = Vector3.zero;
				loadobj.transform.localScale = new Vector3(1f, 1f, 1f);
				chargeui = loadobj.GetComponent<ChargeUI>();
				UnityVersionUtil.SetActiveRecursive(loadobj, state: false);
				break;
			case MenuUIState.showpieceui:
				UnityEngine.Debug.Log("showpieceui load......");
				loadobj = (UnityEngine.Object.Instantiate(Resources.Load("UI/menuui/PieceUI")) as GameObject);
				loadobj.transform.parent = UIrootParent;
				loadobj.transform.localPosition = Vector3.zero;
				loadobj.transform.localScale = new Vector3(1f, 1f, 1f);
				showpieceui = loadobj.GetComponent<ShowPieceUI>();
				UnityVersionUtil.SetActiveRecursive(loadobj, state: false);
				break;
			case MenuUIState.showjunxian:
				UnityEngine.Debug.Log("showjunxian load......");
				loadobj = (UnityEngine.Object.Instantiate(Resources.Load("UI/menuui/JunxianUI")) as GameObject);
				loadobj.transform.parent = UIrootParent;
				loadobj.transform.localPosition = Vector3.zero;
				loadobj.transform.localScale = new Vector3(1f, 1f, 1f);
				junxianui = loadobj.GetComponent<JunxianUI>();
				UnityVersionUtil.SetActiveRecursive(loadobj, state: false);
				break;
            case MenuUIState.showprivacy:
                UnityEngine.Debug.Log("PrivacyPanel");
                loadobj = (UnityEngine.Object.Instantiate(Resources.Load("UI/menuui/PrivacyUI")) as GameObject);
                loadobj.transform.parent = UIrootParent;
                loadobj.transform.localPosition = Vector3.zero;
                loadobj.transform.localScale = new Vector3(1f, 1f, 1f);
                privacyui = loadobj.GetComponent<PrivacyUI>();
                UnityVersionUtil.SetActiveRecursive(loadobj, state: false);
                break;
            case MenuUIState.getpiece:
				UnityEngine.Debug.Log("getpiece load......");
				loadobj = (UnityEngine.Object.Instantiate(Resources.Load("UI/menuui/GetPieceUI")) as GameObject);
				loadobj.transform.parent = UIrootParent;
				loadobj.transform.localPosition = Vector3.zero;
				loadobj.transform.localScale = new Vector3(1f, 1f, 1f);
				getpieceui = loadobj.GetComponent<GetPieceUI>();
				UnityVersionUtil.SetActiveRecursive(loadobj, state: false);
				break;
			case MenuUIState.challinfo:
				UnityEngine.Debug.Log("challinfo load......");
				loadobj = (UnityEngine.Object.Instantiate(Resources.Load("UI/menuui/chall_infoUI")) as GameObject);
				loadobj.transform.parent = UIrootParent;
				loadobj.transform.localPosition = Vector3.zero;
				loadobj.transform.localScale = new Vector3(1f, 1f, 1f);
				challinfoui = loadobj.GetComponent<Chall_infoUI>();
				UnityVersionUtil.SetActiveRecursive(loadobj, state: false);
				break;
		}
	}
}
